package com.openharmony.filepicker.adapter;

import com.openharmony.filepicker.ResourceTable;
import com.openharmony.filepicker.bean.FileModel;
import ohos.agp.components.*;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

public class LcFileAdapter extends RecycleItemProvider {

    private Context mContext;
    private List<FileModel> mDataList = new ArrayList<>();

    public LcFileAdapter(Context mContext, List<FileModel> mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
    }

    @Override
    public int getCount() {
        return mDataList == null ? 0 : mDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return mDataList == null ? null : mDataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        // 获取文件
        FileModel fileModel = mDataList.get(i);
        Component view = LayoutScatter.getInstance(mContext).parse(
                ResourceTable.Layout_layout_lc_item,
                componentContainer,
                false);
        ((Text) view.findComponentById(ResourceTable.Id_tv_name)).setText(fileModel.getFileName());
        ((Image)view.findComponentById(ResourceTable.Id_img_dir_pic)).setPixelMap(
                fileModel.getType() == 0 ? ResourceTable.Media_pic_dir : ResourceTable.Media_pic_file);
        return view;
    }

}
